<%--
  Created by IntelliJ IDEA.
  User: gaosubo3000
  Date: 2020/10/19
  Time: 10:21
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用餐预订</title>
    <link rel="stylesheet" href="/lib/layDate-v5.0.9/laydate/theme/default/laydate.css">
    <link rel="stylesheet" type="text/css" href="/lib/fullcalendar/css/fullcalendar.css"/>
    <link rel="stylesheet" type="text/css" href="/lib/fullcalendar/css/fullcalendar.print.css"/>
    <link rel="stylesheet" type="text/css" href="/css/FullCalendar/style.css"/>
    <link rel="stylesheet" type="text/css" href="/css/base/base.css?20201106.1"/>
    <link rel="stylesheet" type="text/css" href="/lib/pagination/style/pagination.css"/>
    <link rel="stylesheet" href="/lib/layui/layui/css/layui.css">
    <%--    <link rel="stylesheet" href="/lib/layui/layui/css/layui.css?20190817.1">--%>
    <script src="/lib/layDate-v5.0.9/laydate/laydate.js"></script>
    <%--    <script src="/lib/layui/layui/layui.js"></script>--%>
    <script type="text/javascript" src="/js/jquery/jquery-1.9.1.js"></script>
    <script src="/js/common/language.js"></script>
    <script src="/lib/fullcalendar/moment.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery-1.8.3.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/fullcalendar/fullcalendar.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/fullcalendar/zh-cn.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/fullcalendar/jquery-ui.custom.min.js" type="text/javascript" charset="utf-8"></script>

    <script src="/lib/layer/layer.js?20201106"></script>
    <script src="/js/jquery/jquery.cookie.js"></script>
    <script src="/js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/pagination/js/jquery.pagination.min.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" src="/js/base/tablePage.js"></script>
    <script type="text/javascript" src="/lib/layui/layui/layui.js"></script>
</head>
<style>
    .title {
        /*margin-left: 2%;*/
        padding-left: 27px;
        height: 45px;
        line-height: 50px;
        /*border-bottom:1px solid #ccc;*/
        font-size: 22px;
        color: rgb(73, 77, 89);
        font-family: Microsoft yahei,Helvetica Neue,Helvetica,PingFang SC,Tahoma,Arial,sans-serif;
    }
    .titName {
        display: inline-block;
    }
    .colorClass a{
        display: inline-block;
        width:16px;
        height:16px;
        margin-left:10px;
        vertical-align: middle;
    }
    .colorClass{
        color:#666;
        line-height:21px;
        position: absolute;
        right:27px;
        top:13px;
    }
    .fc-event{
        border: none !important;
        background-color: #3a87ad;
        color: #fff;
        font-size: 1.2em;
        cursor: default;
    }
    .layui-form-checkbox i{

        /*border: 1px solid #999;*/
         border-left: 1px solid #999;
    }
</style>
<body>
<div class="title">
    <img src="/img/commonTheme/${sessionScope.InterfaceModel}/dayli.png" alt=""
         style="vertical-align:middle;margin-bottom: 3px">
    <div class="titName" style="margin-left: 7px">用餐预订</div>
</div>
<div class="colorClass">
    <a href="javascript:;" style="background-color: #e5e5e5;"></a>
    <span>可预订用餐的时间</span>
    <a href="javascript:;" style="background-color: rgb(255, 149, 64);"></a>
    <span>早餐</span>
    <a href="javascript:;" style="background-color: rgb(69, 162, 255);"></a>
    <span>午餐</span>

</div>
<div class="box">
    <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
        <ul class="layui-tab-title navs">
            <li class="layui-this Faculty">教职工</li>
            <li class="tourist">访客</li>
        </ul>
        <div class="layui-tab-content" style="height: 100px;">
            <div class="layui-tab-item layui-show">
                <div id="main" style="width:50%;">
                    <div id='calendar'></div>
                </div>
            </div>
            <div class="layui-tab-item layui-show">
                <div id="main2" style="width:50%">
                    <div id='calendar2'></div>
                </div>
            </div>
        </div>
    </div>
</div>

</body>
</html>
<script>
    //当前登录人
    var userName = '', userId = '',deptId = '',deptName = '';
    $.ajax({
        url: '/Meetequipment/getuser',
        type: 'get',
        dataType: 'json',
        success: function (res) {
            userName = res.object.userName
            userId = res.object.userId
            deptId = res.object.deptId
            deptName = res.object.deptName
        }
    })
    layui.use(['element','laydate','form','table'], function(){
        var $ = layui.jquery
            ,element = layui.element,
            form = layui.form,
            table = layui.table,
            laydate = layui.laydate;
        var form = layui.form;


        element.on('tab(docDemoTabBrief)', function(data){
            if(data.index == 0){
                var college  = 1
                var mealType = 2
                eit(college,mealType)
            }else if(data.index == 1){
                var college  = 0
                var mealType = 1
                eit2(college,mealType)
            }
        });

        //常规用法
        //教职工
        eit(1,2)
        function eit(college,mealType){
            var arr=[];
            var arr1=[];
            var arr2=[];
            var arr3=[];
            arr.splice(0, arr.length);//清空数组
            $.ajax({
                url: "/MealManage/getMealMap",
                type: "get",
                dataType: "json",
                data:{
                    mealType : mealType,
                    userName:'admin'
                },
                success: function (data) {
                    var datas = data.obj
                    var arrObject;
                    for(var i=0;i<datas.length;i++){
                        //早餐
                        var predestineTime = datas.predestineTime
                        if(datas[i].breakfastNum !=0 ){
                            var arrObject1 = {
                                title: "早",
                                start: datas[i].predestineTime,
                                end: datas[i].predestineTime,
                                mealId:datas[i].mealId,
                                college:datas[i].college,
                                deptId:datas[i].deptId,
                                deptName:datas[i].deptName,
                                lunchNum:datas[i].lunchNum,
                                mealType:datas[i].mealType,
                                color:"#ff5757",
                                backgroundColor:"rgb(255, 149, 64)",
                                userId:datas[i].userId,
                                userName:datas[i].userName,
                                breakfastNum: datas[i].breakfastNum,
                                height:'10%'
                            };
                        }
                        if(arrObject1 != undefined){
                            arr1.push(arrObject1);
                        }

                        if(datas[i].lunchNum !=0){
                            var arrObject2 = {
                                title: "午",
                                start: datas[i].predestineTime,
                                end: datas[i].predestineTime,
                                mealId:datas[i].mealId,
                                college:datas[i].college,
                                deptId:datas[i].deptId,
                                deptName:datas[i].deptName,
                                lunchNum:datas[i].lunchNum,
                                mealType:datas[i].mealType,
                                color:"#ff5757",
                                backgroundColor:"rgb(69, 162, 255)",
                                userId:datas[i].userId,
                                userName:datas[i].userName,
                                breakfastNum: datas[i].breakfastNum
                            };
                        }
                        if(arrObject2 != undefined){
                            arr2.push(arrObject2);
                        }
                    }
                    arr3 = arr1.concat(arr2)
                    function unique10(arr) {
                        //Set数据结构，它类似于数组，其成员的值都是唯一的
                        return Array.from(new Set(arr)); // 利用Array.from将Set结构转换成数组
                    }
                    var arr = unique10(arr3)
                    var startTime = []
                    for (var i=0;i<arr.length;i++){
                        startTime.push(arr[i].start)
                    }
                    $('#calendar').fullCalendar({
                        header: {
                            left: 'prev,next today',
                            center: 'title',
                            //显示周月日
                            right: 'month'
                        },
                        firstDay:1,
                        editable: true,
                        timeFormat: 'H:mm',
                        axisFormat: 'H:mm',
                        events: arr,
                        dayClick: function (date, allDay, jsEvent, view) {
                            for(var j=0;j<startTime.length;j++){
                                if(date._i == arr[j].start){
                                    if(arr[j].lunchNum != 0 || arr[j].breakfastNum != 0){
                                        layer.msg('已经申请过用餐了！', {icon: 1});
                                        return false
                                    }
                                }
                            }
                            //当前点击日期
                            var thisTime = date._i
                            //当前点击日期时间格式日期
                            var thisTime2 = date._d
                            var date1 = parserDate(thisTime)
                            //下周一
                            var week = letWeek()
                            //下周末
                            var week2 = getWeek()


                            //当前日期
                            var myDate = new Date();
                            var newTime = data_string(myDate)
                            var newTime2 = newTime.split(' ')[0]
                            var newTime3 = parserDate(newTime2)

                            //当前点击前一天
                            var leet = getNextDate(newTime3,+2)
                            var leet2 = parserDate(leet)

                            if(date1 < leet2 || date1 > week2){
                                layer.msg('只能预定当前日期后一天到下周末时间段的！', {icon: 1});
                                return false
                            }
                            // if(date1<week || week2 < date1){
                            //     layer.msg('只能預定下周的！', {icon: 1});
                            //     return false
                            // }

                            layer.open({
                                type: 1,
                                title: '新建',
                                btn: ['确定', '取消'],
                                shade: 0.5,
                                maxmin: true, //开启最大化最小化按钮
                                area: ['30%', '50%'],
                                content:'<form class="layui-form" action="">\n' +
                                    '  <div class="layui-form-item" style="margin-top: 20px;">\n' +
                                    '    <label class="layui-form-label">申请人</label>\n' +
                                    '    <div class="layui-input-inline">\n' +
                                    '      <input type="text" name="userName" userId = "'+userId+'" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input layui-disabled" disabled>\n' +
                                    '    </div>\n' +
                                    '  </div>\n' +
                                    '  <div class="layui-form-item" >\n' +
                                    '    <label class="layui-form-label">部门名称</label>\n' +
                                    '    <div class="layui-input-inline">\n' +
                                    '      <input type="text" name="deptName" deptId = "'+deptId+'" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input layui-disabled" disabled>\n' +
                                    '    </div>\n' +
                                    '  </div>\n' +
                                    '  <div class="layui-form-item" >\n' +
                                    '    <label class="layui-form-label">类别</label>\n' +
                                    '    <div class="layui-input-inline">\n' +
                                    '      <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="教职工" value="" class="layui-input layui-disabled" disabled >\n' +
                                    '    </div>\n' +
                                    '  </div>\n' +
                                    '  <div class="layui-form-item" pane="" style="height: 30px;margin-top: 15px">\n' +
                                    '    <label class="layui-form-label">早餐</label>\n' +
                                    '    <div class="layui-input-inline" style="    width: 13%;">\n' +
                                    '      <input type="checkbox"  lay-skin="primary"  lay-filter="testNum" name="breakfastNumChe" checked>\n' +
                                    '    </div>\n' +
                                    '    <div class="layui-input-inline">\n' +
                                    '      <span>人数</span>'+
                                    '        <input type="text" name="breakfastNum" class="layui-disabled" disabled style="width: 90px;height: 35px;" value="1" onkeyup="this.value=this.value.replace(/\\D|^-1/g,\'\')" onafterpaste="this.value=this.value.replace(/\\D|^0/g,\'\')">\n'+
                                    // '     <input type="number" name="breakfastNum" lay-verify="title" autocomplete="off" class="layui-input" style="width: 50%;display:inline-block;" value="0">\n' +
                                    '    </div>\n' +
                                    '  </div>'    +

                                    '  <div class="layui-form-item" pane="" style="height: 30px;margin-top: 15px">\n' +
                                    '    <label class="layui-form-label">中餐</label>\n' +
                                    '    <div class="layui-input-inline" style="    width: 13%;">\n' +
                                    '      <input type="checkbox"  lay-skin="primary"  lay-filter="testNum2" name="lunchNumChe" checked>\n' +
                                    '    </div>\n' +
                                    '    <div class="layui-input-inline">\n' +
                                    '      <span>人数</span>'+
                                    '        <input type="text" name="lunchNum" style="width: 90px;height: 35px;" class="layui-disabled" disabled value="1" onkeyup="this.value=this.value.replace(/\\D|^0/g,\'\')" onafterpaste="this.value=this.value.replace(/\\D|^0/g,\'\')">\n'+

                                    // '     <input type="number" name="lunchNum" lay-verify="title" autocomplete="off" class="layui-input" style="width: 50%;display:inline-block;" value="0">\n' +
                                    '    </div>\n' +
                                    '  </div>'    +

                                    '</form>',
                                success:function(){
                                    $('input[name="userName"]').val(userName)
                                    $('input[name="deptName"]').val(deptName)
                                    //日期时间选择器
                                    laydate.render({
                                        elem: '#test1'
                                        ,type: 'datetime'
                                    });
                                    form.render();
                                },
                                yes:function (index) {
                                    if($('input[name="breakfastNum"]').val() < 0 || $('input[name="lunchNum"]').val() < 0){
                                        layer.msg('请输入正确的人数！', {icon: 1});
                                        return false
                                    }
                                    $.ajax({
                                        url: '/MealManage/editMealMap',
                                        type: 'get',
                                        dataType: 'json',
                                        data:{
                                            userId : $('input[name="userName"]').attr('userId'),
                                            deptId : $('input[name="deptName"]').attr('deptId'),
                                            breakfastNum : $('input[name="breakfastNum"]').val(),
                                            lunchNum : $('input[name="lunchNum"]').val(),
                                            college : college,
                                            mealType: mealType,
                                            predestineTime : data_string(thisTime2)
                                        },
                                        success: function (res) {
                                            location.reload();
                                        }
                                    })
                                }
                            })
                        },
                        eventClick:function (calEvent, jsEvent, view){
                            //隔天修改
                            var leet = getNextDate(calEvent.start._i,-2)
                            var myDate = new Date();
                            var newTime = data_string(myDate)
                            var newTime2 = newTime.split(' ')[0]
                            var leet2 = parserDate(leet)
                            var newTime3 = parserDate(newTime2)
                            if(newTime3 > leet2){
                                layer.msg('请在用餐前一天编辑！', {icon: 1});
                                return false
                            }
                            var mealId = calEvent.mealId
                            var thisTime2 = calEvent.start._d
                            var userIdEid = calEvent.userName
                            var deptIdEid = calEvent.deptName

                            var mealTypeText = ''
                            if(calEvent.mealType == 2){
                                mealTypeText = '教职工'
                            }else {
                                mealTypeText = '访客'
                            }
                            layer.open({
                                type: 1,
                                title: '编辑',
                                btn: ['确定', '取消','删除'],
                                shade: 0.5,
                                maxmin: true, //开启最大化最小化按钮
                                area: ['30%', '50%'],
                                content:'<form class="layui-form" action="">\n' +
                                    '  <div class="layui-form-item" style="margin-top: 20px;">\n' +
                                    '    <label class="layui-form-label">申请人</label>\n' +
                                    '    <div class="layui-input-inline">\n' +
                                    '      <input type="text" name="userName" userId = "'+calEvent.userId+'" value="'+userIdEid+'" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input layui-disabled" disabled>\n' +
                                    '    </div>\n' +
                                    '  </div>\n' +
                                    '  <div class="layui-form-item" >\n' +
                                    '    <label class="layui-form-label">部门名称</label>\n' +
                                    '    <div class="layui-input-inline">\n' +
                                    '      <input type="text" name="deptName" deptId = "'+calEvent.deptId+'" value="'+deptIdEid+'" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input layui-disabled" disabled>\n' +
                                    '    </div>\n' +
                                    '  </div>\n' +
                                    '  <div class="layui-form-item" >\n' +
                                    '    <label class="layui-form-label">类别</label>\n' +
                                    '    <div class="layui-input-inline">\n' +
                                    '      <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="教职工" value="'+mealTypeText+'" class="layui-input layui-disabled" disabled >\n' +
                                    // '      <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="教职工" value="" class="layui-input layui-disabled" disabled >\n' +
                                    '    </div>\n' +
                                    '  </div>\n' +
                                    '  <div class="layui-form-item" pane="" style="height: 30px;margin-top: 15px">\n' +
                                    '    <label class="layui-form-label">早餐</label>\n' +
                                    '    <div class="layui-input-inline" style="    width: 13%;">\n' +
                                    '      <input type="checkbox"  lay-skin="primary"  lay-filter="testNum" name="breakfastNumChe" checked>\n' +
                                    '    </div>\n' +
                                    '    <div class="layui-input-inline">\n' +
                                    '      <span>人数</span>'+
                                    '        <input type="text" name="breakfastNum" style="width: 90px;height: 35px;" class="layui-disabled" disabled  value="'+calEvent.breakfastNum+'" onkeyup="this.value=this.value.replace(/\\D|^-1/g,\'\')" onafterpaste="this.value=this.value.replace(/\\D|^0/g,\'\')">\n'+
                                    // '     <input type="number" name="breakfastNum" lay-verify="title" autocomplete="off" class="layui-input" style="width: 50%;display:inline-block;" value="0">\n' +
                                    '    </div>\n' +
                                    '  </div>'    +

                                    '  <div class="layui-form-item" pane="" style="height: 30px;margin-top: 15px">\n' +
                                    '    <label class="layui-form-label">中餐</label>\n' +
                                    '    <div class="layui-input-inline" style="    width: 13%;">\n' +
                                    '      <input type="checkbox"  lay-skin="primary" name="lunchNumChe"  lay-filter="testNum2" checked>\n' +
                                    '    </div>\n' +
                                    '    <div class="layui-input-inline">\n' +
                                    '      <span>人数</span>'+
                                    '        <input type="text" name="lunchNum" style="width: 90px;height: 35px;" class="layui-disabled" disabled  value="'+calEvent.lunchNum+'" onkeyup="this.value=this.value.replace(/\\D|^0/g,\'\')" onafterpaste="this.value=this.value.replace(/\\D|^0/g,\'\')">\n'+

                                    // '     <input type="number" name="lunchNum" lay-verify="title" autocomplete="off" class="layui-input" style="width: 50%;display:inline-block;" value="0">\n' +
                                    '    </div>\n' +
                                    '  </div>'    +

                                    '</form>',
                                success:function(res){
                                    $('input[name="userName"]').val(userName)
                                    $('input[name="deptName"]').val(deptName)
                                    laydate.render({
                                        elem: '#test1'
                                        ,type: 'datetime'
                                    });
                                    if($('input[name="breakfastNum"]').val() == 0){
                                        $('input[name="breakfastNumChe"]').attr('checked',false)
                                    }
                                    if($('input[name="lunchNum"]').val() == 0){
                                        $('input[name="lunchNumChe"]').attr('checked',false)
                                    }

                                    form.render();
                                },
                                yes:function(index){
                                    if($('input[name="breakfastNum"]').val() < 0 || $('input[name="lunchNum"]').val() < 0){
                                        layer.msg('请输入正确的人数！', {icon: 1});
                                        return false
                                    }

                                    $.ajax({
                                        url: '/MealManage/editMealMap',
                                        type: 'get',
                                        dataType: 'json',
                                        data:{
                                            mealId:mealId,
                                            userId : $('input[name="userName"]').attr('userId'),
                                            deptId : $('input[name="deptName"]').attr('deptId'),
                                            breakfastNum : $('input[name="breakfastNum"]').val(),
                                            lunchNum : $('input[name="lunchNum"]').val(),
                                            college : college,
                                            mealType: mealType,
                                            predestineTime : data_string(thisTime2)
                                        },
                                        success: function (res) {
                                            location.reload();
                                        }
                                    })
                                },
                                btn3:function(){
                                    $.ajax({
                                        url: '/MealManage/delMealId',
                                        type: 'get',
                                        dataType: 'json',
                                        data:{
                                            mealId:mealId
                                        },
                                        success: function (res) {
                                            location.reload();
                                        }
                                    })
                                }
                            })
                        },
                        dayRender: function (date, cell) {

                            //当前日期
                            var myDate = new Date();
                            var newTime = data_string(myDate)
                            var newTime2 = newTime.split(' ')[0]
                            var newTime3 = parserDate(newTime2)

                            //当前日期前一天
                            var leet = getNextDate(newTime3,+2)
                            var leet3 = parserDate(leet)

                            //下周一
                            var timeThis3 = letWeek()
                            var timeThis5= new Date(timeThis3)
                            var timeThis4 = data_string(timeThis5)
                            //当前页面显示日期
                            var timeThis = date._d
                            var timeThis2 = data_string(timeThis)
                            //下周日
                            var timeThis6 = getWeek()
                            // if (date.isSame(timeThis5)) {
                            //     cell.css("background-color","red");
                            // }
                            if(parserDate(timeThis2) >= leet3 && parserDate(timeThis2)<= timeThis6){
                                cell.css("background-color","#e5e6e6");
                            }

                        }
                    });
                }
            })
        }
        //    访客
        function eit2(college,mealType){
            var arr=[];
            var arr1=[];
            var arr2=[];
            var arr3=[];
            arr.splice(0, arr.length);//清空数组
            $.ajax({
                url: "/MealManage/getMealMap",
                type: "get",
                dataType: "json",
                data:{
                    mealType : mealType,
                    userName:'admin'
                },
                success: function (data) {
                    var datas = data.obj
                    var arrObject;
                    for(var i=0;i<datas.length;i++){
                        //早餐
                        var predestineTime = datas.predestineTime
                        if(datas[i].breakfastNum !=0 ){
                            var arrObject1 = {
                                title: "早",
                                start: datas[i].predestineTime,
                                end: datas[i].predestineTime,
                                mealId:datas[i].mealId,
                                college:datas[i].college,
                                deptId:datas[i].deptId,
                                deptName:datas[i].deptName,
                                lunchNum:datas[i].lunchNum,
                                mealType:datas[i].mealType,
                                color:"#ff5757",
                                backgroundColor:"rgb(255, 149, 64)",
                                userId:datas[i].userId,
                                userName:datas[i].userName,
                                breakfastNum: datas[i].breakfastNum,
                                height:'10%'
                            };
                        }
                        if(arrObject1 != undefined){
                            arr1.push(arrObject1);
                        }

                        if(datas[i].lunchNum !=0){
                            var arrObject2 = {
                                title: "午",
                                start: datas[i].predestineTime,
                                end: datas[i].predestineTime,
                                mealId:datas[i].mealId,
                                college:datas[i].college,
                                deptId:datas[i].deptId,
                                deptName:datas[i].deptName,
                                lunchNum:datas[i].lunchNum,
                                mealType:datas[i].mealType,
                                color:"#ff5757",
                                backgroundColor:"rgb(69, 162, 255)",
                                userId:datas[i].userId,
                                userName:datas[i].userName,
                                breakfastNum: datas[i].breakfastNum
                            };
                        }
                        if(arrObject2 != undefined){
                            arr2.push(arrObject2);
                        }


                    }
                    arr3 = arr1.concat(arr2)
                    function unique10(arr) {
                        //Set数据结构，它类似于数组，其成员的值都是唯一的
                        return Array.from(new Set(arr)); // 利用Array.from将Set结构转换成数组
                    }
                    var arr = unique10(arr3)
                    var startTime = []
                    for (var i=0;i<arr.length;i++){
                        startTime.push(arr[i].start)
                    }
                    $('#calendar2').fullCalendar({
                        header: {
                            left: 'prev,next today',
                            center: 'title',
                            //显示周月日
                            right: 'month'
                        },
                        firstDay:1,
                        editable: true,
                        timeFormat: 'H:mm',
                        axisFormat: 'H:mm',
                        events: arr,
                        dayClick: function (date, allDay, jsEvent, view) {
                            //当前点击日期
                            var thisTime = date._i
                            //当前点击日期时间格式日期
                            var thisTime2 = date._d
                            var date1 = parserDate(thisTime)
                            //下周一
                            var week = letWeek()
                            //下周末
                            var week2 = getWeek()


                            //当前日期
                            var myDate = new Date();
                            var newTime = data_string(myDate)
                            var newTime2 = newTime.split(' ')[0]
                            var newTime3 = parserDate(newTime2)

                            //当前点击前一天
                            var leet = getNextDate(newTime3,+2)
                            var leet2 = parserDate(leet)

                            if(date1 < leet2 || date1 > week2){
                                layer.msg('只能预定当前日期后一天到下周末时间段的！', {icon: 1});
                                return false
                            }
                            for(var j=0;j<startTime.length;j++){
                                if(date._i == arr[j].start){
                                    if(arr[j].lunchNum != 0 || arr[j].breakfastNum != 0){
                                        console.log(arr[j])
                                        layer.msg('已经申请过用餐了！', {icon: 1});
                                        return false
                                    }
                                }
                            }
                            layer.open({
                                type: 1,
                                title: '新建',
                                btn: ['确定', '取消'],
                                shade: 0.5,
                                maxmin: true, //开启最大化最小化按钮
                                area: ['30%', '50%'],
                                content:'<form class="layui-form" action="">\n' +
                                    '  <div class="layui-form-item" style="margin-top: 20px;">\n' +
                                    '    <label class="layui-form-label">申请人</label>\n' +
                                    '    <div class="layui-input-inline">\n' +
                                    '      <input type="text" name="userName" userId = "'+userId+'" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input layui-disabled" disabled>\n' +
                                    '    </div>\n' +
                                    '  </div>\n' +
                                    '  <div class="layui-form-item" >\n' +
                                    '    <label class="layui-form-label">部门名称</label>\n' +
                                    '    <div class="layui-input-inline">\n' +
                                    '      <input type="text" name="deptName" deptId = "'+deptId+'" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input layui-disabled" disabled>\n' +
                                    '    </div>\n' +
                                    '  </div>\n' +
                                    '  <div class="layui-form-item" >\n' +
                                    '    <label class="layui-form-label">类别</label>\n' +
                                    '    <div class="layui-input-inline">\n' +
                                    '      <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="访客" value="" class="layui-input layui-disabled" disabled >\n' +
                                    '    </div>\n' +
                                    '  </div>\n' +
                                    '  <div class="layui-form-item" pane="" style="height: 30px;margin-top: 15px">\n' +
                                    '    <label class="layui-form-label">早餐</label>\n' +
                                    '    <div class="layui-input-inline block" style="width: 13%;">\n' +
                                    '      <input  class="break"  type="checkbox"  lay-skin="primary" name="breakfastNumChe" lay-filter="testNum">\n' +
                                    '    </div>\n' +
                                    '    <div class="layui-input-inline">\n' +
                                    '      <span>人数</span>'+
                                    '        <input type="text" name="breakfastNum" style="width: 90px;height: 35px;" value="0" onkeyup="this.value=this.value.replace(/\\D|^-1/g,\'\')" onafterpaste="this.value=this.value.replace(/\\D|^0/g,\'\')">\n'+
                                    '    </div>\n' +
                                    '  </div>'    +

                                    '  <div class="layui-form-item" pane="" style="height: 30px;margin-top: 15px">\n' +
                                    '    <label class="layui-form-label">中餐</label>\n' +
                                    '    <div class="layui-input-inline" style="    width: 13%;">\n' +
                                    '      <input type="checkbox"  lay-skin="primary" name="lunchNumChe"  lay-filter="testNum2">\n' +
                                    '    </div>\n' +
                                    '    <div class="layui-input-inline">\n' +
                                    '      <span>人数</span>'+
                                    '        <input type="text" name="lunchNum" style="width: 90px;height: 35px;" value="0" onkeyup="this.value=this.value.replace(/\\D|^0/g,\'\')" onafterpaste="this.value=this.value.replace(/\\D|^0/g,\'\')">\n'+

                                    // '     <input type="number" name="lunchNum" lay-verify="title" autocomplete="off" class="layui-input" style="width: 50%;display:inline-block;" value="0">\n' +
                                    '    </div>\n' +
                                    '  </div>'    +

                                    '</form>',
                                success:function(){

                                    $('input[name="userName"]').val(userName)
                                    $('input[name="deptName"]').val(deptName)

                                    //日期时间选择器
                                    laydate.render({
                                        elem: '#test1'
                                        ,type: 'datetime'
                                    });

                                    form.render();
                                },
                                yes:function (index) {
                                    if($('input[name="breakfastNum"]').val() < 0 || $('input[name="lunchNum"]').val() < 0){
                                        layer.msg('请输入正确的人数！', {icon: 1});
                                        return false
                                    }
                                    var breakfastNum = ''
                                    var lunchNum = ''
                                    if($('input[name="breakfastNumChe"]').attr('checked')){
                                        breakfastNum =  $('input[name="breakfastNum"]').val()
                                        // breakfastNum = $('input[name="lunchNum"]').val()
                                    }else {
                                        breakfastNum = 0
                                    }
                                    if($('input[name="lunchNumChe"]').attr('checked')){
                                        lunchNum =  $('input[name="lunchNum"]').val()
                                    }else {
                                        lunchNum = 0
                                    }
                                    $.ajax({
                                        url: '/MealManage/editMealMap',
                                        type: 'get',
                                        dataType: 'json',
                                        data:{
                                            userId : $('input[name="userName"]').attr('userId'),
                                            deptId : $('input[name="deptName"]').attr('deptId'),
                                            breakfastNum : breakfastNum,
                                            lunchNum : lunchNum,
                                            college : college,
                                            mealType: mealType,
                                            predestineTime : data_string(thisTime2)
                                        },
                                        success: function (res) {
                                            location.reload();
                                        }
                                    })
                                }
                            })
                        },
                        eventClick:function (calEvent, jsEvent, view){
                            //隔天修改
                            var leet = getNextDate(calEvent.start._i,-2)
                            var myDate = new Date();
                            var newTime = data_string(myDate)
                            var newTime2 = newTime.split(' ')[0]
                            var leet2 = parserDate(leet)
                            var newTime3 = parserDate(newTime2)
                            if(newTime3 > leet2){
                                layer.msg('请在用餐前一天编辑！', {icon: 1});
                                return false
                            }
                            var mealId = calEvent.mealId
                            var thisTime2 = calEvent.start._d
                            var userIdEid = calEvent.userName
                            var deptIdEid = calEvent.deptName
                            var  breakfastNumChe = ''
                            var lunchNumChe = ''
                            if(calEvent.breakfastNum >0){
                                breakfastNumChe = true
                            }else {
                                breakfastNumChe = false
                            }

                            if(calEvent.lunchNum >0){
                                lunchNumChe = true
                            }else {
                                lunchNumChe = false
                            }
                            layer.open({
                                type: 1,
                                title: '编辑',
                                btn: ['确定', '取消','删除'],
                                shade: 0.5,
                                maxmin: true, //开启最大化最小化按钮
                                area: ['30%', '50%'],
                                content:'<form class="layui-form" action="">\n' +
                                    '  <div class="layui-form-item" style="margin-top: 20px;">\n' +
                                    '    <label class="layui-form-label">申请人</label>\n' +
                                    '    <div class="layui-input-inline">\n' +
                                    '      <input type="text" name="userName" userId = "'+calEvent.userId+'" value="'+userIdEid+'" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input layui-disabled" disabled>\n' +
                                    '    </div>\n' +
                                    '  </div>\n' +
                                    '  <div class="layui-form-item" >\n' +
                                    '    <label class="layui-form-label">部门名称</label>\n' +
                                    '    <div class="layui-input-inline">\n' +
                                    '      <input type="text" name="deptName" deptId = "'+calEvent.deptId+'" value="'+deptIdEid+'" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input layui-disabled" disabled>\n' +
                                    '    </div>\n' +
                                    '  </div>\n' +
                                    '  <div class="layui-form-item" >\n' +
                                    '    <label class="layui-form-label">类别</label>\n' +
                                    '    <div class="layui-input-inline">\n' +
                                    '      <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="访客" value="" class="layui-input layui-disabled" disabled >\n' +
                                    // '      <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="教职工" value="" class="layui-input layui-disabled" disabled >\n' +
                                    '    </div>\n' +
                                    '  </div>\n' +
                                    '  <div class="layui-form-item" pane="" style="height: 30px;margin-top: 15px">\n' +
                                    '    <label class="layui-form-label">早餐</label>\n' +
                                    '    <div class="layui-input-inline" style="    width: 13%;">\n' +
                                    '      <input type="checkbox"  lay-skin="primary" name="breakfastNumChe" checked="'+breakfastNumChe+'" lay-filter="testNum">\n' +
                                    '    </div>\n' +
                                    '    <div class="layui-input-inline">\n' +
                                    '      <span>人数</span>'+
                                    '        <input type="text" name="breakfastNum" style="width: 90px;height: 35px;"  value="'+calEvent.breakfastNum+'" onkeyup="this.value=this.value.replace(/\\D|^-1/g,\'\')" onafterpaste="this.value=this.value.replace(/\\D|^0/g,\'\')">\n'+
                                    // '     <input type="number" name="breakfastNum" lay-verify="title" autocomplete="off" class="layui-input" style="width: 50%;display:inline-block;" value="0">\n' +
                                    '    </div>\n' +
                                    '  </div>'    +

                                    '  <div class="layui-form-item" pane="" style="height: 30px;margin-top: 15px">\n' +
                                    '    <label class="layui-form-label">中餐</label>\n' +
                                    '    <div class="layui-input-inline" style="    width: 13%;">\n' +
                                    '      <input type="checkbox"  lay-skin="primary" name="lunchNumChe" checked="'+lunchNumChe+'" lay-filter="testNum2">\n' +
                                    '    </div>\n' +
                                    '    <div class="layui-input-inline">\n' +
                                    '      <span>人数</span>'+
                                    '        <input type="text" name="lunchNum" style="width: 90px;height: 35px;" value="'+calEvent.lunchNum+'" onkeyup="this.value=this.value.replace(/\\D|^0/g,\'\')" onafterpaste="this.value=this.value.replace(/\\D|^0/g,\'\')">\n'+

                                    // '     <input type="number" name="lunchNum" lay-verify="title" autocomplete="off" class="layui-input" style="width: 50%;display:inline-block;" value="0">\n' +
                                    '    </div>\n' +
                                    '  </div>'    +

                                    '</form>',
                                success:function(res){
                                    $('input[name="userName"]').val(userName)
                                    $('input[name="deptName"]').val(deptName)
                                    laydate.render({
                                        elem: '#test1'
                                        ,type: 'datetime'
                                    });
                                    if($('input[name="breakfastNum"]').val() == 0){
                                        $('input[name="breakfastNumChe"]').attr('checked',false)
                                    }
                                    if($('input[name="lunchNum"]').val() == 0){
                                        $('input[name="lunchNumChe"]').attr('checked',false)
                                    }
                                    form.render();
                                },
                                yes:function(index){

                                    if($('input[name="breakfastNum"]').val() < 0 || $('input[name="lunchNum"]').val() < 0){
                                        layer.msg('请输入正确的人数！', {icon: 1});
                                        return false
                                    }

                                    $.ajax({
                                        url: '/MealManage/editMealMap',
                                        type: 'get',
                                        dataType: 'json',
                                        data:{
                                            mealId:mealId,
                                            userId : $('input[name="userName"]').attr('userId'),
                                            deptId : $('input[name="deptName"]').attr('deptId'),
                                            breakfastNum : $('input[name="breakfastNum"]').val(),
                                            lunchNum : $('input[name="lunchNum"]').val(),
                                            college : college,
                                            mealType: mealType,
                                            predestineTime : data_string(thisTime2)
                                        },
                                        success: function (res) {
                                            location.reload();
                                        }
                                    })
                                },
                                btn3:function(){
                                    $.ajax({
                                        url: '/MealManage/delMealId',
                                        type: 'get',
                                        dataType: 'json',
                                        data:{
                                            mealId:mealId
                                        },
                                        success: function (res) {
                                            location.reload();
                                        }
                                    })
                                }
                            })
                        },
                        dayRender: function (date, cell) {
                            //当前日期
                            var myDate = new Date();
                            var newTime = data_string(myDate)
                            var newTime2 = newTime.split(' ')[0]
                            var newTime3 = parserDate(newTime2)

                            //当前日期前一天
                            var leet = getNextDate(newTime3,+2)
                            var leet3 = parserDate(leet)

                            //下周一
                            var timeThis3 = letWeek()
                            var timeThis5= new Date(timeThis3)
                            var timeThis4 = data_string(timeThis5)
                            //当前页面显示日期
                            var timeThis = date._d
                            var timeThis2 = data_string(timeThis)
                            //下周日
                            var timeThis6 = getWeek()
                            // if (date.isSame(timeThis5)) {
                            //     cell.css("background-color","red");
                            // }
                            if(parserDate(timeThis2) >= leet3 && parserDate(timeThis2)<= timeThis6){
                                cell.css("background-color","#e5e6e6");
                            }

                        }
                    });
                }
            })


        }


        //监听复选框、
        form.on('checkbox(testNum)', function(data){
          if(data.elem.checked){
              $('input[name="breakfastNum"]').val('1');
          }else {
              $('input[name="breakfastNum"]').val('0');
          }
        });
        form.on('checkbox(testNum2)', function(data){
            if(data.elem.checked){
                $('input[name="lunchNum"]').val('1');
            }else {
                $('input[name="lunchNum"]').val('0');
            }
        });
    });


    //时间日期转换成string
    function data_string(now) {
        var yy = now.getFullYear();      //年
        var mm = now.getMonth() + 1;     //月
        var dd = now.getDate();          //日
        var hh = now.getHours();         //时
        var ii = now.getMinutes();       //分
        var ss = now.getSeconds();       //秒
        var clock = yy + "-";
        if(mm < 10) clock += "0";
        clock += mm + "-";
        if(dd < 10) clock += "0";
        clock += dd + " ";
        if(hh < 10) clock += "0";
        clock += hh + ":";
        if (ii < 10) clock += '0';
        clock += ii + ":";
        if (ss < 10) clock += '0';
        clock += ss;
        return clock;
    }
    //时间戳
    function parserDate(date) {
        var date = Date.parse(date)
        return date
    }
    //下周一
    function letWeek() {
        var Stamp;
        Stamp = new Date();
        var num = 7-Stamp.getDay()+1;
        Stamp.setDate(Stamp.getDate() + num);

        var year = Stamp.getFullYear(); //获取完整的年份(4位,1970-????)
        var month = Stamp.getMonth() +1; //获取当前月份(0-11,0代表1月)
        var mvar ='';
        if(month<10){
            mvar = '0' + month;
        }else{
            mvar = month+'';
        }
        var day = Stamp.getDate();
        var dvar ='';
        if(day<10){
            dvar = '0' + day;
        }else{
            dvar = day+'';
        }
        var week = parserDate(year+"-"+mvar+'-'+dvar)

        return week
    }
    //后一天
    function getNextDate(date,day) {
        var dd = new Date(date);
        dd.setDate(dd.getDate() + day);
        var y = dd.getFullYear();
        var m = dd.getMonth() + 1 < 10 ? "0" + (dd.getMonth() + 1) : dd.getMonth() + 1;
        var d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();
        var getNextDate = y + "-" + m + "-" + d;
        return getNextDate
    }
    //下周末
    function getWeek() {
        const weeks = [];
        for (let i = 0; i < 7; i++) {
            let Stamp = new Date();
            let num = 7-Stamp.getDay() + 1 + i;
            Stamp.setDate(Stamp.getDate() + num);
            weeks[i] = Stamp.getFullYear()+'-'+(Stamp.getMonth() + 1) + '-' + Stamp.getDate() ;

        }
        // console.log(weeks[6]);
        var week2 = parserDate(weeks[6])
        return week2;
    }


</script>
